#### Appendix 7.2: Dictionary Approach to Speaker Topics ####

source("./code/loadPackages.R") # Install and load necessary packages

#### Load necessary data ####
mad = fread("./data/dictionaryData.csv")   # Counts of key words based on dictionary
nscd_all = fread("./data/meetingData.csv") # Meeting-level data

#### Table A41: Speaker Hawkishness and Speech Act Content ####
# See "dictionaryAnalysis.R."


#### Appendix 7.3: President's Hawkishness and Topic Prevalence ####
# Calculate mean level of topic proportions at meeting level, removing presidents
meanProps = mad |> filter(president==0) |> 
  group_by(meetNum) |> dplyr::select(starts_with("prop"), doctype) |> 
  summarize(meanViolence=mean(propViolence),
            meanThreat=mean(propThreat),
            meanBalance=mean(propBalance),
            meanDiplo=mean(propDiplo),
            meanAdv=mean(propAdv)) 

# Add other data that we need
meetStats = mad |> group_by(meetNum) |> dplyr::select(formal, doctype) |> slice(1) # Meeting statistics 
ph = nscd_all |> dplyr::select(meetNum, presHawk, admin)                           # Presidents' hawkishness

# Combine data
meanProps = merge(meanProps, ph, by="meetNum")
meanProps = merge(meanProps, meetStats, by="meetNum")

## Do regressions ##
violence_pres = lm(meanViolence ~ presHawk + formal + I(doctype=="Transcript"), data=meanProps)

threat_pres = lm(meanThreat ~ presHawk + formal + I(doctype=="Transcript"), data=meanProps)

balance_pres = lm(meanBalance ~ presHawk + formal + I(doctype=="Transcript"), data=meanProps)

diplo_pres = lm(meanDiplo ~ presHawk + formal + I(doctype=="Transcript"), data=meanProps)

adversary_pres = lm(meanAdv ~ presHawk + formal + I(doctype=="Transcript"), data=meanProps)


#### Table A42: President's Hawkishness and Speech Act Content ####
stargazer(violence_pres, threat_pres, balance_pres, diplo_pres, adversary_pres,
          no.space=T,
          align=T,omit.stat=c("f","ser","adj.rsq","rsq"),digits=4,
          covariate.labels = c("President's Hawkishness", "Formal", "Transcript"))
